import { export_json_to_excel } from './Export2Excel';
var getGlobal={
    getItem(key){
        let item = localStorage.getItem(key)
        if(item){
            return JSON.parse(item)
        }else{
            return null
        }
    },
    setItem(key , value){
        localStorage.setItem(key,JSON.stringify(value))
    },
    deleteItem(key){
        if(localStorage.getItem(key)){
            localStorage.removeItem(key)
        }
        return null
    },
    getCookie(name){
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)")
        if(arr = document.cookie.match(reg)) {
            return arr[2]
        } else {
            return null
        }
    },
    setCookie(name,value,minute){
        // var minute = 30
        var exp = new Date()
        exp.setTime(exp.getTime()+minute*60*1000)
        document.cookie=name+"="+value+";expires="+exp.toGMTString()
    },

    delCookie(name){
        var exp = new Date()
        exp.setTime(exp.getTime()-1)
        var cval = this.getCookie(name)
        if(cval != null){
            console.log('enter delCookie')
            document.cookie = name+"="+cval+";expires="+exp.toGMTString()
        }
    },
    //导出功能 excelName 表名 tHeader 表头 filterVal 导出字段  list导出值
    exportFun(excelName,tHeader,filterVal,list){
        const data = this.excelFormatJson(filterVal, list)
        export_json_to_excel(tHeader, data, excelName)
    },
    //转json
    excelFormatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
    },
    // message统一报错
    messageError(){

    }
}

export default getGlobal
